<template>
	<view>
		<view class="p-2">
			<view>
				<view class="bt-block">
					<bg-cell2 label="姓名" :value="obj.realName"></bg-cell2>
					<bg-cell2 label="性别">
						<template slot="value">
							<bg-label :options="dict.type.sys_user_sex" :value="obj.gender"></bg-label>
						</template>
					</bg-cell2>
					<bg-cell2 label="身份证" :value="obj.idCardNo"></bg-cell2>
					<bg-cell2 label="联系方式" :border="false" :value="obj.phone"></bg-cell2>
				</view>
			</view>
			<view class="mt-2 bt-block">
				<bg-cell2 label="手持身份证照片">
					<template slot="extra">
						<view>
							<u--image @click="previewImg(obj.handledIdCardUrl)" :src="obj.handledIdCardUrl" width="100%"
								height="184px"></u--image>
						</view>
					</template>
				</bg-cell2>
				<bg-cell2 label="工作岗位" :value="obj.workPost">
					<template slot="value">
						<bg-label :options="dict.type.work_post" :value="obj.workPost"></bg-label>
					</template>
				</bg-cell2>
				<bg-cell2 label="工种" :value="obj.workJobTypeName"></bg-cell2>
				<bg-cell2 label="入职项目" :value="obj.projectName"></bg-cell2>
				<bg-cell2 label="用工期限" :value="obj.workDeadline"></bg-cell2>
				<bg-cell2 label="报酬方式" :value="obj.salaryType">
					<template slot="value">
						<bg-label :options="salaryTypes" :value="obj.salaryType"></bg-label>
					</template>
				</bg-cell2>
				<bg-cell2 v-if="obj.salaryType == 1" label="日薪" :value="obj.daySalaryAmount"></bg-cell2>
				<bg-cell2 v-if="obj.salaryType == 2" label="月薪" :value="obj.monthSalaryAmount"></bg-cell2>
				<bg-cell2 v-if="obj.salaryType == 3" label="时薪"
					:value="obj.meteringAmount + obj.meteringUnit"></bg-cell2>
				<bg-cell2 label="发薪日期" :value="`每月${obj.payDay}日`"></bg-cell2>
				<bg-cell2 label="合同类别" :value="obj.contractType">
					<template slot="value">
						<text class="font-1 text-grey2">临时用工合同</text>
					</template>
				</bg-cell2>
				<bg-cell2 :border="false" label="入场日期" :value="obj.createTime"></bg-cell2>
			</view>
			<view class="bt-block my-3">
				<bg-title class="margin-top mx-3">
					<text class="font-1">流程节点图</text>
				</bg-title>
				<view class="p-3">
					<bg-step :list="authList"></bg-step>
				</view>
			</view>
			<view class="" style="height: 200rpx;"></view>

		</view>
		<!-- <view class="bt-footer bt-gap"> -->
		<view class="bt-footer bt-gap"
			v-if="obj.status == 1 && this.$auth.hasRoleOr(['project']) && obj.auditUserId == $store.getters.userId">
			<bg-btn plain @click="showReason = true">审批未通过</bg-btn>
			<bg-btn @click="audit(2)">审批通过</bg-btn>
		</view>
		<!-- 填写拒绝理由弹窗 -->
		<u-popup :show="showReason" @close="showReason = false" @open="showReason = true" :closeable="true" :round="10"
			mode="center">
			<view style="width: 720rpx; padding: 30rpx;">
				<view class="text-center font-15 font-bold mb-4">{{ '填写理由' }}</view>
				<u-textarea v-model="reason" placeholder="请输入拒绝理由"></u-textarea>
				<view class="bt-gap flex justify-around" style="margin-top: 60rpx;">
					<bg-btn @click="showReason = false"
						style="height:90rpx; color: #86898c;background-color: #fafafa; border: none;">取消</bg-btn>
					<bg-btn @click="ReasonConfirm" style="height:90rpx">确定</bg-btn>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
import {
	getEntry,
	entryAudit
} from "@/api/entry.js"
import {
	salaryTypes
} from "@/utils/constant.js"
export default {
	dicts: ["sys_user_sex", "emergency_type", "contract_type", "work_post"],
	props: ["propId"],
	data() {
		return {
			salaryTypes: salaryTypes,
			id: '',
			obj: '',
			authList: [],
			// 拒绝弹窗
			showReason: false,
			reason: ''
		}
	},
	onLoad(options) {
		this.id = options.id

	},
	mounted() {
		this.getData()
	},
	methods: {
		previewImg(url) {
			uni.previewImage({
				current: url,
				urls: [url]
			})
		},
		getData() {
			if (!this.id && this.propId) {
				this.id = this.propId
			}
			getEntry(this.id).then(res => {
				this.obj = res.data
				if (res.data.userAge > 55) {
					let workPost = res.data.workPost == 1 ? "工人" : "班组管理员"
					uni.showModal({
						title: '提示',
						content: `该${workPost}年龄超过55周岁，存在年龄风险，请注意`,
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								// uni.navigateBack()
							}
						}
					})
				}
				this.authList = [{
					auditUserName: this.obj.realName,
					auditTime: this.obj.createTime
				},
				...this.obj.auditRecordList
				]
			})
		},
		audit(status) {
			let method = null
			if (this.$auth.hasRole("project")) {
				method = entryAudit
			}
			if (method) {
				let obj = {
					id: this.obj.auditId,
					status: status
				}
				if (status == 3) {
					obj.reason = this.reason
				}
				method(obj).then(res => {
					this.$modal.msg('审批成功')
					uni.$emit("refresh-settle", true)
					uni.navigateBack()
					// uni.redirectTo({
					// 	url: '/pages/enter/enter/index'
					// })
					// uni.$emit("refresh-enter", this.$store.getters.projectId)
					// this.$tab.navigateBackDelay()
				})
			}
		},
		ReasonConfirm() {
			if (this.reason.trim() == '') {
				this.$modal.msg('请输入拒绝理由')
				return
			}
			this.showReason = false
			this.audit(3)
		}
	}
}
</script>

<style></style>